package com.zy.集合.常用方法.wordCount

object Test {

  def main(args: Array[String]): Unit = {

    val list: List[String] = List("Hello java", "Hello scala", "Hello spark", "Hello Hadoop", "Hello spark", "Hello java")

    val map: Map[String, List[String]] = list.flatMap(_.split(" ")).groupBy(str => str)
    val map1: Map[String, Int] = map.map(kv => (kv._1, kv._2.length))
    val list1: List[(String, Int)] = map1.toList.sortWith(_._2 > _._2).take(3)
    println(list1)
  }
}
